﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Canvas & Bitmap</title>
<meta name="GENERATOR" content="WinCHM">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>
<P><FONT face=Arial size=2><STRONG><A style="COLOR: rgb(0,102,153)" 
href="http://developer.android.com/guide/topics/media/mediaplayer.html">Save Bitgmap to file</A></STRONG></FONT><FONT face=Arial size=2><BR><A 
href="http://java.dzone.com/articles/adjusting-opacity-android"><FONT 
face="Times New Roman" 
size=3>http://java.dzone.com/articles/adjusting-opacity-android</FONT></A><BR></FONT>        </P>
<P><FONT face=Arial size=2></FONT>        &nbsp;</P>
<H1>đoạn code lấy Canvas từ Bitmap ( chuẩn&nbsp;)        </H1>
<P><FONT face=Arial size=2>        /**<BR>* 
@param bitmap The source bitmap.<BR>* @param opacity a value between 0 
(completely transparent) and 255 (completely<BR>* opaque).<BR>* @return The 
opacity-adjusted bitmap.&nbsp; If the source bitmap is mutable it will be<BR>* 
adjusted and returned, otherwise a new bitmap is created.<BR>*/<BR>private Bitmap <FONT 
color=#0000ff><EM><STRONG>adjustOpacity</STRONG></EM></FONT> 
 (Bitmap bitmap, int opacity)<BR>{<BR><FONT style="BACKGROUND-COLOR: #ffff00"><STRONG>&nbsp;&nbsp;&nbsp;&nbsp; Bitmap</STRONG> mutableBitmap = 
bitmap.<STRONG>isMutable</STRONG>() ? bitmap : 
bitmap.copy(Bitmap.Config.ARGB_8888, <STRONG>true</STRONG> 
);</FONT>  
<BR><FONT 
style="BACKGROUND-COLOR: #ffff00"><STRONG>&nbsp;&nbsp;&nbsp;&nbsp; Canvas</STRONG> canvas = <STRONG>new</STRONG> </FONT> 
<STRONG><FONT 
style="BACKGROUND-COLOR: #ffff00">   
Canvas(mutableBitmap);</FONT>     <BR>&nbsp;&nbsp;&nbsp;&nbsp; int colour =   (opacity 
&amp; 0xFF) &lt;&lt; 24;<BR>&nbsp;&nbsp;&nbsp;&nbsp; canvas.<EM><FONT color=#0000ff>drawColor</FONT></EM>(colour, 
PorterDuff.Mode.DST_IN);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return mutableBitmap;<BR>        }</P>
<DIV class="line alt1" 
style="BORDER-TOP-WIDTH: 0px; PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; WORD-SPACING: 0px; FONT: 12px Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; VERTICAL-ALIGN: baseline; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; PADDING-TOP: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(231,229,220); TEXT-ALIGN: left; BORDER-RIGHT-WIDTH: 0px; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px; outline-width: 0px; outline-style: initial; outline-color: initial"><SPAN 
class=content 
style="BORDER-TOP-WIDTH: 0px; PADDING-RIGHT: 0px; DISPLAY: block; PADDING-LEFT: 0.5em; FONT-WEIGHT: normal; FONT-SIZE: 12px; RIGHT: auto; LEFT: auto; FLOAT: none; BACKGROUND-IMAGE: none; BORDER-BOTTOM-WIDTH: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 0px 3.3em; VERTICAL-ALIGN: baseline; BORDER-LEFT: rgb(108,226,108) 3px solid; WIDTH: auto; COLOR: rgb(0,0,0); BOTTOM: auto; LINE-HEIGHT: normal; PADDING-TOP: 0px; FONT-STYLE: normal; FONT-FAMILY: Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; POSITION: static; TOP: auto; HEIGHT: auto; BACKGROUND-COLOR: rgb(255,255,255); TEXT-ALIGN: left; BORDER-RIGHT-WIDTH: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; background-origin: initial; background-clip: initial"></SPAN></DIV></FONT></STRONG></body>
</html>
